﻿#ifndef ERRDATAFILEREADER_H
#define ERRDATAFILEREADER_H

#include "stdafx.h"
#include <IDib.h>

#include "opencv2/opencv.hpp"

//extern BOOL CErrDataBase_Serialize(CArchive& ar, BOOL bCompress);

//extern bool new_CErrDataBase_Serialize(CArchive& ar, BOOL bCompress);

struct itemDesc{
    QString fileName; //输出文件名
    int pcbNumber;
    bool isTop;
    int qcIndex;
    int qcType;
    QVector<cv::Rect> rects;
    bool isTrue;

    QString orgFilename;//原始文件名
    QString filePath;//原始文件所在路径
};

class nItem;
class ErrDataFileReader
{
public:
    ErrDataFileReader(const QString &errDataFile);
    ~ErrDataFileReader(){
        if(m_arErr)
        {
            m_arErr->Close();
            delete m_arErr;
        }
        if(m_FileErr)
        {
            m_FileErr->Close();
            delete m_FileErr;
        }
        if(m_arTrue)
        {
            m_arTrue->Close();
            delete m_arTrue;
        }
        if(m_FileTrue)
        {
            m_FileTrue->Close();
            delete m_FileTrue;
        }
    }

    void readItems();
    void readTrue();
    QPair<QString,QStringList> saveOutPutFile(int workmode, bool checkTF);

    QPair<QString,QStringList> saveOutPutFile(int workmode, bool checkTF, const QString& outpath, const QString& inpath);

    itemDesc getResultStr();

    static bool checkErrDataFile(const QString &file);

    static bool blockCheckErrDataFile(const QString &file, bool &error, int timeout);

private:
    void errDataBaseSerialize();
    void errTrueSerialize();

private:
    bool isTop = false; //是否是顶部
    QString pcbNumber; //板子序号

    QString dataPath;
    QString errFile;
    QString trueFile;

    QVector<nItem*> items;

    CFile * m_FileErr= nullptr;
    CFile * m_FileTrue = nullptr;

    CArchive *m_arTrue= nullptr;
    CArchive *m_arErr= nullptr;

    bool hasError = true;
signals:

public slots:
};

#endif // ERRDATAFILEREADER_H
